/*
 * perceptron.cpp
 *
 *  Created on: Feb 28, 2011
 *      Author: tqlong
 */

#include "perceptron.h"
#include <armadillo>

using namespace arma;

void Perceptron::setParameters(const std::vector<double>& params)
{
  if (params.size() > 0) alpha_ = params[0];
}

double Perceptron::update(const vec& x, double y, double p)
{
  double error = 0.5 * (y - p);
  w_ += alpha_ * error * x;
  return error;
}

double Perceptron::predict(const arma::vec& x) {
  double y = dot(w_, x);
  predict_ = y > 0 ? 1 : -1;
  return predict_;
}
